package com.san.hkhospital.service.impl;

import com.san.hkhospital.dto.Medicine1;
import com.san.hkhospital.entity.StateExample;
import com.san.hkhospital.vo.MedicineVo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.san.hkhospital.mapper.MedicineMapper;

import java.math.BigDecimal;
import java.util.List;
import com.san.hkhospital.entity.Medicine;
import com.san.hkhospital.entity.MedicineExample;
import com.san.hkhospital.service.MedicineService;
import org.springframework.transaction.annotation.Transactional;

/**
 * ClassName:MedicineServiceImpl
 * PackageName:com.san.hkhospital.service.impl
 * Description:
 *
 * @Author:yy
 * @CreatedAt:2024/11/13 14:38
 * 
 */
 
 
@Service
@Transactional
public class MedicineServiceImpl implements MedicineService{

    @Resource
    private MedicineMapper medicineMapper;

    @Override
    public long countByExample(MedicineExample example) {
        return medicineMapper.countByExample(example);
    }

    @Override
    public int deleteByExample(MedicineExample example) {
        return medicineMapper.deleteByExample(example);
    }

    @Override
    public int deleteByPrimaryKey(Integer medId) {
        return medicineMapper.deleteByPrimaryKey(medId);
    }

    @Override
    public int insert(Medicine record) {
        return medicineMapper.insert(record);
    }

    @Override
    public int insertSelective(Medicine record) {
        return medicineMapper.insertSelective(record);
    }

    @Override
    public List<Medicine> selectByExample(MedicineExample example) {
        return medicineMapper.selectByExample(example);
    }

    @Override
    public Medicine selectByPrimaryKey(Integer medId) {
        return medicineMapper.selectByPrimaryKey(medId);
    }

    @Override
    public int updateByExampleSelective(Medicine record,MedicineExample example) {
        return medicineMapper.updateByExampleSelective(record,example);
    }

    @Override
    public int updateByExample(Medicine record,MedicineExample example) {
        return medicineMapper.updateByExample(record,example);
    }

    @Override
    public int updateByPrimaryKeySelective(Medicine record) {
        return medicineMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Medicine record) {
        return medicineMapper.updateByPrimaryKey(record);
    }

    ///////////////////////////////////////////////////////////////////////////////////////

    //显示所有
    @Override
    public List<Medicine> medicineList() {
        return medicineMapper.selectByExample(null);
    }

    //添加药品
    @Override
    public boolean addMedicine(Medicine medicine) {
        return medicineMapper.insertSelective(medicine)>0?true:false;
    }

    //删除药品
    @Override
    public boolean deleteMedicine(Integer id) {
        return medicineMapper.deleteByPrimaryKey(id)>0?true:false;
    }

    //修改药品价格
    @Override
    public boolean updateMedPrice(Integer medId, Double medPrice) {
        Medicine medicine = new Medicine();
        medicine.setMedId(medId);
        medicine.setMedPrice(new BigDecimal(medPrice));
        int i = medicineMapper.updateByPrimaryKeySelective(medicine);
        return i>0?true:false;
    }

    //修改药品全部信息
    @Override
    public int updateMedicine(Medicine medicine) {
        return medicineMapper.updateByPrimaryKeySelective(medicine);
    }

    @Override
    public List<MedicineVo> search(Medicine1 medicine1) {
        List<MedicineVo> search = medicineMapper.search(medicine1);
        return search;
    }



}
